package com.ws.shop.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.ws.shop.bean.Page;
import com.ws.shop.dao.LetterDao;
import com.ws.shop.entity.Letter;
import com.ws.shop.service.LetterService;

@Service(value="letterService")
public class LetterServiceImpl implements LetterService {
	@Resource(name="letterDao")
	private LetterDao letterDao;

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Page findLetterListPage(long pageno,int pagesize) {
		return letterDao.findLetterListPage(pageno,pagesize);
	}

	@Transactional(rollbackFor=Exception.class)
	public void sendAllLetter(Letter letter) {
		letterDao.sendAllLetter(letter);
	}

	@Transactional(rollbackFor=Exception.class)
	public void sendLetter(Letter letter) {
		letterDao.sendLetter(letter);
	}

	public List<Letter> getLetters(int type,String username){
		return letterDao.getLetters(type, username);
	}
	
	@Transactional(rollbackFor=Exception.class)
	public int updateState(int type,String username){
		return letterDao.updateState(type, username);
	}
	
	@Transactional(rollbackFor=Exception.class)
	public int delLetter(int type,long id,String username){
		return letterDao.delLetter(type, id, username);
	}
	@Transactional(rollbackFor=Exception.class)
	public int sendMessage(Letter letter){
		return letterDao.sendMessage(letter);
	}
	
	public int getLetterCount(String name,int state ){
		return letterDao.getLetterCount(name, state);
	}
	
	public Page getLetterByUserId(long pageno, int pagesize,String username){
		return letterDao.getLetterByUserId(pageno, pagesize, username);
	}
}
